//
//  IMTBatteryModel.m
//  INMOTION
//
//  Created by 方人疋 on 2017/9/27.
//  Copyright © 2017年 Inmotion. All rights reserved.
//

#import "IMTBatteryModel.h"
#import "IMFunction.h"

@implementation IMTBatteryModel

- (void)loadBatteryDeviceInfoWithData:(NSData *)data {
    if (data.length >= 21) {
        uint16_t specifiedCapacity = 0;
        [data getBytes:&specifiedCapacity range:NSMakeRange(0, 2)];
        self.specifiedCapacity = specifiedCapacity;
        
        uint16_t actualCapacity = 0;
        [data getBytes:&actualCapacity range:NSMakeRange(2, 2)];
        self.actualCapacity = actualCapacity;
        
//        uint16_t specifiedVoltage = 0;
//        [data getBytes:&specifiedVoltage range:NSMakeRange(4, 2)];
        
        uint16_t recyclingCount = 0;
        [data getBytes:&recyclingCount range:NSMakeRange(6, 2)];
        self.recyclingCount = recyclingCount;
        
        char sn[13] = {0};
        [data getBytes:sn range:NSMakeRange(8, 13)];
        self.sn = [NSString stringWithCString:sn encoding:NSUTF8StringEncoding];
    }
}

- (void)loadBatteryStateInfoWithData:(NSData *)data {
    if (data.length >= 12) {
        uint16_t leftCapacity = 0;
        [data getBytes:&leftCapacity range:NSMakeRange(1, 2)];
        self.leftCapacity = leftCapacity;
        
        uint16_t voltage = 0;
        [data getBytes:&voltage range:NSMakeRange(3, 2)];
        self.voltage = voltage / 1000.0;
        
        int16_t current = 0;
        [data getBytes:&current range:NSMakeRange(5, 2)];
        self.current = current / 10.0;
        
        int16_t temperature1 = 0;
        [data getBytes:&temperature1 range:NSMakeRange(7, 2)];
        self.temperature1 = temperature1;
        
        int16_t temperature2 = 0;
        [data getBytes:&temperature2 range:NSMakeRange(9, 2)];
        self.temperature2 = temperature2;
        
        uint8_t status = 0;
        [data getBytes:&status range:NSMakeRange(11, 1)];
        self.status = status;
    }
}

@end
